package com.CityHunter.Request;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;

import android.util.Log;

import com.CityHunter.Common.Http;

public class UpdateStateRequest {

	private String updateStatePage;
	
	public UpdateStateRequest(String updateStatePage){
		this.updateStatePage = updateStatePage;
	}
	
	public int updateState(int userid,int state){
		int result = 0;
		
		// Declare NameValuePair to store the data
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("state", Integer
				.toString(state)));
		params.add(new BasicNameValuePair("userid", Integer
				.toString(userid)));
		
		Http http = new Http();
		Log.d("abdy_Debug", "Sending Request : " + updateStatePage);
		
		JSONArray jsonResponse = http.sendRequest(updateStatePage, params);
		try {
			result = Integer.parseInt(jsonResponse.getJSONObject(0)
					.getString("result"));
			Log.d("Sttp_Debug", "Update State Result: " + result);
		} catch (Exception e) {
			Log.e("Sttp_Error", e.getMessage().toString());
		}
		
		return result;
	}
}
